<?php

use think\facade\Route;

// 测试接口
Route::get("test", "Index/index")->name("test");
Route::get("subscribe", "Index/subscribe")->name("subscribe");
Route::get("publish", "Index/publish")->name("publish");

// 定时访问的几口
Route::get("timeAccess", "Index/timeStruct")->name("timeAccess");
// 支付回调接口
/*Route::any('wechat/serve', 'wechat.WechatController/serve');//公众号服务
Route::any('wechat/notify', 'wechat.WechatController/notify');//公众号支付回调*/
Route::any('routine/notify', 'wechat.AuthController/notify');//小程序支付回调

// 未授权接口
Route::group(function () {
    // 公共类
    Route::get("index", "PublicController/index")->name("index");   // 首页 【已经完成】

    //小程序登陆
    Route::post('wechat/mp_auth', 'wechat.AuthController/mp_auth')->name('mpAuth');//小程序登陆  【已经完成】
    Route::get('wechat/get_logo', 'wechat.AuthController/get_logo')->name('getLogo');//小程序登陆授权展示logo 【已经完成】
    Route::post('wechat/set_form_id', 'wechat.AuthController/set_form_id')->name('setFormId');//小程序登陆收集form id 【已经完成】
    Route::get('wechat/teml_ids', 'wechat.AuthController/teml_ids')->name('wechatTemlIds');//微信授权 【已经完成】

    Route::get('meallist', 'user.UserController/mealList')->name('mealList');// 积分套餐    【√】
    Route::get('storelist', 'store.IndexController/storeList')->name('storeList');// 门店列表    【√】
    // 个人中心部分
    Route::get("help/about", "store.IndexController/aboutUs")->name("aboutUs"); // 关于我们
    Route::get("help/question", "store.IndexController/helpQuestion")->name("helpQuestion"); // 关于我们

    // 获取存在的城市的列表的数据
    Route::get("list/store/:city_id", "store.IndexController/listStore")->name("listStore"); // 门店列表
    Route::get("cityList", "store.IndexController/cityList")->name("cityList"); // 获取所有的城市列表

    Route::get('couponData', 'user.UserController/couponData')->name('couponData'); // 购买积分
    Route::get("storeInfo", "order.StoreOrderCarController/storeInfo")->name("storeInfo");  // 门店的详情
    Route::get("isReceive", "user.UserController/isReceive")->name("isReceive");    // 是否领取优惠券
    Route::get("washInfo", "PublicController/washInfo")->name("washInfo");    // 洗车信息
    Route::get("userAgreement", "PublicController/userAgreement")->name("userAgreement");    // 洗车信息

})->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, false);


// 需要授权的接口
Route::group(function () {
    Route::get('logout', 'AuthController/logout')->name('logout');// 退出登录   【×】
    Route::post('binding', 'AuthController/binding_phone')->name('bindingPhone');// 绑定手机号【×】

    //公共类
    Route::post('upload/image', 'PublicController/upload_image')->name('uploadImage');//图片上传

    //用户类  用户coupons/order
    Route::get('user', 'user.UserController/user')->name('user');//个人中心
    Route::post('user/edit', 'user.UserController/edit')->name('userEdit');//用户修改信息
    Route::get('user/balance', 'user.UserController/balance')->name('userBalance');//用户资金统计
    Route::get('userinfo', 'user.UserController/userinfo')->name('userinfo');// 用户信息    【√】
    Route::get('cashlog', 'user.UserController/cashLog')->name('washLog');// 用户洗车的记录    【√】


    //优惠券类
    Route::post('coupon/receive', 'store.StoreCouponsController/receive')->name('couponReceive'); //领取优惠券
    Route::post('coupon/receive/batch', 'store.StoreCouponsController/receive_batch')->name('couponReceiveBatch'); //批量领取优惠券
    Route::get('coupons/user/:types', 'store.StoreCouponsController/user')->name('couponsUser');//用户已领取优惠券
    Route::get('coupons/order/:price', 'store.StoreCouponsController/order')->name('couponsOrder');//优惠券 订单列表
    Route::get('coupons/list', 'store.StoreCouponsController/lst')->name('couponsList');//优惠券 订单列表  【√】

    // 车辆类
    Route::get("car/list", "user.CarController/lst")->name("carList");  // 所有的车辆
    Route::post("car/add", "user.CarController/add")->name("carAdd");  // 添加车辆
    Route::post("car/edit", "user.CarController/edit")->name("carEdit");  // 编辑车辆
    Route::post("car/del/:car_id", "user.CarController/del")->name("carEdit");  // 删除车辆

    //订单类
    Route::post('order/confirm', 'order.StoreOrderController/confirm')->name('orderConfirm'); //订单确认
    Route::post('order/computed/:key', 'order.StoreOrderController/computedOrder')->name('computedOrder'); //计算订单金额
    Route::post('order/create/:key', 'order.StoreOrderController/create')->name('orderCreate'); //订单创建
    // Route::get('order/data', 'order.StoreOrderController/data')->name('orderData'); //订单统计数据
    Route::get('order/list', 'order.StoreOrderCarController/lst')->name('orderList'); //订单列表   【√】
    // Route::get('order/detail/:uni', 'order.StoreOrderController/detail')->name('orderDetail'); //订单详情
    Route::get('order/refund/reason', 'order.StoreOrderController/refund_reason')->name('orderRefundReason'); //订单退款理由
    Route::post('order/refund/verify', 'order.StoreOrderController/refund_verify')->name('orderRefundVerify'); //订单退款审核
    // Route::post('order/take', 'order.StoreOrderController/take')->name('orderTake'); //订单收货
    // Route::get('order/express/:uni', 'order.StoreOrderController/express')->name('orderExpress'); //订单查看物流
    // Route::post('order/del', 'order.StoreOrderController/del')->name('orderDel'); //订单删除
    // Route::post('order/again', 'order.StoreOrderController/again')->name('orderAgain'); //订单 再次下单
    Route::post('order/pay', 'order.StoreOrderController/pay')->name('orderPay'); //订单支付

    // 积分
    Route::any("buyPoint", 'user.UserController/buyPoint')->name("buyPoint");   // 购买积分
    // 绑定手机号
    Route::post("bindPhone", "user.UserController/bindPhone")->name("bindPhone");   // 绑定手机号

    Route::any("uploadfile", "publicController/upload_image")->name("file");    // 上传文件
    Route::post('productOption', 'user.UserController/productOption')->name('productOption');   // 评论
    Route::post('removeImg/:file_id', 'publicController/remove_img')->name("remove_img");    // 删除图片
    Route::get('pointLog', 'user.UserController/pointLog')->name('pointLog');   // 积分日志
    Route::any('buyCoupon', 'user.UserController/buyCoupon')->name('buyCoupon'); // 购买积分
    // 洗车支付
    Route::any("washCar", "order.StoreOrderCarController/washCar")->name("washCar");    // 洗车
    Route::get("orderDetail", "order.StoreOrderCarController/orderDetail")->name("orderDetail");    // 订单详情
    Route::get("machineMsg/:device_id", "order.StoreOrderCarController/machineMsg")->name("machineMsg");   // 设备的信息
    Route::post("send", "order.StoreOrderCarController/send")->name("sendMsg");
    Route::get("receiveCoupon", "user.UserController/receiveCoupon")->name("receiveCoupon");    // 领取优惠券
    Route::get("judge", "order.StoreOrderCarController/judge")->name("judge");   // 判断是否洗车

})->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);


//分享配置
Route::get('share', 'PublicController/share')->name('share');//分享配置


// 接口不存在的时候
Route::miss(function () {
    if (app()->request->isOptions())
        return \think\Response::create('ok')->code(200)->header([
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Allow-Headers' => 'Authori-zation,Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
            'Access-Control-Allow-Methods' => 'GET,POST,PATCH,PUT,DELETE,OPTIONS,DELETE',
        ]);
    else
        return \think\Response::create()->code(404);
});